SeqData<-read.delim("RTGI.GO.071408", header=F, sep="\t", quote="", dec=".") nrow(SeqData) #202805 SeqName<-read.table("Seq_name.txt", header=T) nrow(SeqName)#13937 AddCol<-function(FileName1, FileName2) {#make null vector and add to File1 colvec<-NULL for (ii in 1:length(FileName1[,1])) {if(ii==FileName2[,1]) found=T colvec<-c(colvec, ii) #if column 1 matches term in File2, then make a new column (colvec) with that name until find another term from file2 } Data<-cbind(colvec, FileName1) } AddCol(SeqData, SeqName) Ex3 <- function() { # Read in the data FileName <- "I:\\Lect2.csv" TheData <- read.table(FileName,sep=',') Nmax <- max(TheData[,2]) # Create a list of zero length Slopes <- NULL # Work through each animal in turn for (Ipop in 1:Nmax) { # Extract the data for this animal TheDat1 <- TheData[TheData[,2]==Ipop,] # If enough data if (length(TheDat1[,1]) > 1) { RegOut <- lm(TheDat1[,4]~TheDat1[,3]) TheSlope <- coefficients(RegOut)[2] Slopes <- c(Slopes,TheSlope) } } hist(Slopes,xlab="Slope",main="") }